package com.ruoyi.stat.toilet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.standingbook.v2toilet.domain.V2ToiletBill;
import com.ruoyi.standingbook.v2toilet.domain.bo.V2ToiletBillBo;
import com.ruoyi.standingbook.v2toilet.domain.vo.V2ToiletBillVo;
import com.ruoyi.standingbook.v2toilet.mapper.V2ToiletBillMapper;
import com.ruoyi.stat.toilet.domain.bo.CommunityToiletStatBo;
import com.ruoyi.stat.toilet.domain.bo.V2ToiletBillStatBo;
import com.ruoyi.stat.toilet.domain.vo.V2ToiletBillStatVo;
import com.ruoyi.stat.toilet.mapper.V2ToiletBillStatMapper;
import com.ruoyi.stat.toilet.service.IV2ToiletBillStatService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 电子档案公厕数据统计汇总Service接口实现
 *
 * @author zf
 * @date 2023-06-10
 */
@RequiredArgsConstructor
@Service
public class V2ToiletBillStatService implements IV2ToiletBillStatService {

    private final V2ToiletBillMapper baseMapper;

    private final V2ToiletBillStatMapper statMapper;

    @Override
    public TableDataInfo<V2ToiletBillVo> getToiletImgs(V2ToiletBillBo bo, PageQuery pageQuery) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<V2ToiletBill> lqw = Wrappers.lambdaQuery();
        lqw.eq(Objects.isNull(bo.getStatus()), V2ToiletBill::getStatus, bo.getStatus());
        lqw.between(params.get("beginDate") != null && params.get("endDate") != null,
            V2ToiletBill::getCreateTime, params.get("beginDate"), params.get("endDate"));
        Page<V2ToiletBillVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    @Override
    public List<V2ToiletBillStatVo> queryToiletImgs(CommunityToiletStatBo communityToiletStatBo){
        return statMapper.queryToiletImgs(communityToiletStatBo);
    }

    @Override
    public List<V2ToiletBillStatVo> queryToiletBillByDate(CommunityToiletStatBo communityToiletStatBo){
        return statMapper.queryToiletBillByDate(communityToiletStatBo);
    }

    @Override
    public List<V2ToiletBillStatVo> queryToiletBillByMonth(CommunityToiletStatBo communityToiletStatBo){
        return statMapper.queryToiletBillByMonth(communityToiletStatBo);
    }

    @Override
    public List<V2ToiletBillStatVo> getToiletBills(V2ToiletBillStatBo bo){
        return statMapper.getToiletBills(bo);
    }

    @Override
    public Integer getToiletBillCount(V2ToiletBillStatBo bo){
        return statMapper.getToiletBillCount(bo);
    }
}
